package com.stylefeng.guns.modular.biz.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.common.constant.factory.PageFactory;
import com.stylefeng.guns.common.exception.BizExceptionEnum;
import com.stylefeng.guns.common.exception.BussinessException;
import com.stylefeng.guns.common.persistence.dao.ProductFlowMapper;
import com.stylefeng.guns.common.persistence.dao.ProductInfoMapper;
import com.stylefeng.guns.common.persistence.model.ProductFlow;
import com.stylefeng.guns.common.persistence.model.ProductInfo;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.biz.dao.ProductDao;
import com.stylefeng.guns.modular.biz.dao.ProductFlowDao;
import com.stylefeng.guns.modular.biz.warpper.ProductFlowWarpper;
import com.stylefeng.guns.modular.biz.warpper.ProductWarpper;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 产品信息控制器
 *
 * @author fengshuonan
 * @Date 2017-10-15 14:16:34
 */
@Controller
@RequestMapping("/productFlow")
public class ProductFlowController extends BaseController {

    private String PREFIX = "/biz/productFlow/";

    @Resource
    private ProductFlowDao productFlowDao;



    /**
     * 跳转到产品信息首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "productFlow.html";
    }


    /**
     * 获取产品信息列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam(required = false) String bizType,@RequestParam(required = false) String productMode) {
        Page<ProductFlow> page = new PageFactory<ProductFlow>().defaultPage();
        Integer deptid= ShiroKit.getUser().getDeptId();//获取当前用户部门id
        if(ShiroKit.getUser().getDeptId()==27){//超级管理员
            deptid=null;
        }
        List<Map<String, Object>> result = productFlowDao.getProductFlows(page ,deptid,bizType, productMode ,page.getOrderByField(), page.isAsc()) ;
        page.setRecords((List<ProductFlow>) new ProductFlowWarpper(result).warp());
        return super.packForBT(page);
    }


}
